package com.example.administrator.szb.util;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;


/**
 * Created by stone on 2018/1/2.
 */

public class ShareUtils {
    private static Context context = SampleApplicationLike.getInstance();
    public static void share(Activity activity,String imgurl, String openUrl, String title,String content) {
        UMWeb web = new UMWeb(""+openUrl);
        web.setTitle(""+title);//标题
        if (TextUtils.isEmpty(content)){
            content=title;
        }
        web.setDescription(content);
        if (imgurl==null){
            imgurl = URLAddress.HOST_PORT+"/uploads/szb_icon.jpg";
        }
        UMImage thumb = new UMImage(context, imgurl);

        web.setThumb(thumb);  //缩略图
        new ShareAction(activity)
                .withMedia(web)
                .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ,SHARE_MEDIA.QZONE, SHARE_MEDIA.WEIXIN,SHARE_MEDIA.WEIXIN_CIRCLE)
                .setCallback(new UMShareListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {
                        //Toasts.show(context, "start", Toast.LENGTH_SHORT);
                    }

                    @Override
                    public void onResult(SHARE_MEDIA share_media) {
                        Toasts.show(context, "分享成功", Toast.LENGTH_SHORT);
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                        Toasts.show(context, "" + throwable.toString(), Toast.LENGTH_SHORT);
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media) {

                    }
                })
                .open();
    }
}
